/*
  Copyright 2008 Google Inc.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */ 

package pat.solitaire;

import pat.solitaire.R;

import android.content.SharedPreferences;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class Solution {

    public Solution(final OldFrenchSolitaire solitaire, final SolitaireView view) {
	int score=0;
	solitaire.setContentView(R.layout.solution);
	View statsView = (View) solitaire.findViewById(R.id.solution_view);
	statsView.setFocusable(true);
	statsView.setFocusableInTouchMode(true);
	
	Rules rules = view.GetRules();
	TextView tv = (TextView)solitaire.findViewById(R.id.text_title);
	tv.setText(rules.GetPrettyGameTypeString() + ": Test for a solution\n\n");

	/* Recherche d'une solution */

	/* Affichage des résultats */

	if(score>=10) {
	    tv = (TextView)solitaire.findViewById(R.id.text_ein);
	    tv.setText("The initial configurartion had solutions.");
	    tv = (TextView)solitaire.findViewById(R.id.text_zwei);
	    tv.setText("The best score possible was : " + score);
	    tv = (TextView)solitaire.findViewById(R.id.text_drei);
	    tv.setText("You fail and must start a new game.");
	}
	else {
	    tv = (TextView)solitaire.findViewById(R.id.text_ein);
	    //tv.setText("The initial configuration had no solution.");
	    tv.setText("Not yet implemented");
	    tv = (TextView)solitaire.findViewById(R.id.text_zwei);
	    tv.setText("Will be implemented in the following version.");
	}	
	final Button accept = (Button) solitaire.findViewById(R.id.button_accept);
	accept.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
		    view.InitGame(Rules.PSSOLITAIRE);
		    solitaire.CancelOptions();
		}
	    });
	statsView.setOnKeyListener(new View.OnKeyListener() {
		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event) {
		    switch (keyCode) {
		    case KeyEvent.KEYCODE_BACK:
		    case KeyEvent.KEYCODE_HOME:
			return true;
		    }
		    return false;
		}
	    });
	statsView.requestFocus();
    }
}

